package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseAttrInfo;
import com.atguigu.gmall.product.entity.BaseCategory1;
import com.atguigu.gmall.product.entity.BaseCategory2;
import com.atguigu.gmall.product.entity.BaseCategory3;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseCategory2Service;
import com.atguigu.gmall.product.service.BaseCategory3Service;
import com.atguigu.gmall.product.service.BaseCategoryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.tomcat.util.modeler.AttributeInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("admin/product")
@Api(tags = "三级分类管理")
public class BaseCategoryController {

    @Autowired
    private BaseCategoryService baseCategoryService;
    @Autowired
    private BaseCategory2Service baseCategory2Service;

    @Autowired
    private BaseCategory3Service baseCategory3Service;


    @ApiOperation("查询所有的一级分类")
    @GetMapping("/getCategory1")
    public Result getCategory(){

        List<BaseCategory1> category1s = baseCategoryService.list();

        return Result.ok(category1s);
    }
    @ApiOperation("根据一级分类Id查询二级分类")
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable Long category1Id){

     List<BaseCategory2> category2s =  baseCategory2Service.getCateGory2ByC1Id(category1Id);


        return Result.ok(category2s);
    }
    @ApiOperation("根据二级分类Id查询三级分类")
    @GetMapping("/getCategory3/{c2id}")
    public  Result getCategory3(@PathVariable("c2id") Long c2Id ){
        List<BaseCategory3> category3s =  baseCategory3Service.getCateGory3ByC2Id(c2Id);
        return Result.ok(category3s);
    }


}
